#include <iostream>
using namespace std;
    
struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

int smallest_but_not(TreeNode* root,int nothis)
{
    if(root == nullptr) return -1;
    if(root->val != nothis)
    {
        return root->val;
    }
    int left = smallest_but_not(root->left,nothis);
    int right = smallest_but_not(root->right,nothis);
    if(left == -1 && right != -1)
        return right;
    if(left != -1 && right == -1)
        return left;
    if(left != -1 && right != -1)
        return (left < right)?(left):(right);
    return -1;
}    
    
int findSecondMinimumValue(TreeNode* root) {
    return smallest_but_not(root,root->val);
}

int main(int argc, char const *argv[])
{
    return 0;
}
